package com.diorsunion.hedge.client.borker.ib;

import com.diorsunion.hedge.client.borker.BorkerBO;
import com.diorsunion.hedge.io.IOClient;
import com.diorsunion.hedge.util.LogUtil;
import com.ib.client.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by harley-dog on 2016/5/6.
 */
@Component
public class IBWrapper implements EWrapper {

    @Resource
    BorkerBO borkerBO;

    public IBWrapper() {
        LogUtil.info("IBWrapper()");
    }

    @Override
    public void tickPrice(int tickerId, int field, double price, int canAutoExecute) {

        LogUtil.info("tickPrice()");
    }

    @Override
    public void tickSize(int tickerId, int field, int size) {

        LogUtil.info("tickSize()");
    }

    @Override
    public void tickOptionComputation(int tickerId, int field, double impliedVol, double delta, double optPrice, double pvDividend, double gamma, double vega, double theta, double undPrice) {

        LogUtil.info("tickOptionComputation()");
    }

    @Override
    public void tickGeneric(int tickerId, int tickType, double value) {

        LogUtil.info("tickGeneric()");
    }

    @Override
    public void tickString(int tickerId, int tickType, String value) {

        LogUtil.info("tickString()");
    }

    @Override
    public void tickEFP(int tickerId, int tickType, double basisPoints, String formattedBasisPoints, double impliedFuture, int holdDays, String futureExpiry, double dividendImpact, double dividendsToExpiry) {

        LogUtil.info("tickEFP()");
    }

    @Override
    public void orderStatus(int orderId, String status, int filled, int remaining, double avgFillPrice, int permId, int parentId, double lastFillPrice, int clientId, String whyHeld) {

        LogUtil.info("orderStatus()");
    }

    @Override
    public void openOrder(int orderId, Contract contract, Order order, OrderState orderState) {

        LogUtil.info("openOrder()");
    }

    @Override
    public void openOrderEnd() {

        LogUtil.info("openOrderEnd()");
    }

    @Override
    public void updateAccountValue(String key, String value, String currency, String accountName) {

        LogUtil.info("updateAccountValue()");
    }

    @Override
    public void updatePortfolio(Contract contract, int position, double marketPrice, double marketValue, double averageCost, double unrealizedPNL, double realizedPNL, String accountName) {

        LogUtil.info("updatePortfolio()");
    }

    @Override
    public void updateAccountTime(String timeStamp) {

        LogUtil.info("updateAccountTime()");
    }

    @Override
    public void accountDownloadEnd(String accountName) {

        LogUtil.info("accountDownloadEnd()");
    }

    @Override
    public void nextValidId(int orderId) {

        LogUtil.info("nextValidId()");
    }

    @Override
    public void contractDetails(int reqId, ContractDetails contractDetails) {

        LogUtil.info("contractDetails()");
    }

    @Override
    public void bondContractDetails(int reqId, ContractDetails contractDetails) {

        LogUtil.info("bondContractDetails()");
    }

    @Override
    public void contractDetailsEnd(int reqId) {

        LogUtil.info("contractDetailsEnd()");
    }

    @Override
    public void execDetails(int reqId, Contract contract, Execution execution) {

        LogUtil.info("execDetails()");
    }

    @Override
    public void execDetailsEnd(int reqId) {

        LogUtil.info("execDetailsEnd()");
    }

    @Override
    public void updateMktDepth(int tickerId, int position, int operation, int side, double price, int size) {

        LogUtil.info("updateMktDepth()");
    }

    @Override
    public void updateMktDepthL2(int tickerId, int position, String marketMaker, int operation, int side, double price, int size) {

        LogUtil.info("updateMktDepthL2()");
    }

    @Override
    public void updateNewsBulletin(int msgId, int msgType, String message, String origExchange) {

        LogUtil.info("updateNewsBulletin()");
    }

    @Override
    public void managedAccounts(String accountsList) {
        borkerBO.onConnect(accountsList);
    }

    @Override
    public void receiveFA(int faDataType, String xml) {

        LogUtil.info("receiveFA()");
    }

    @Override
    public void historicalData(int reqId, String date, double open, double high, double low, double close, int volume, int count, double WAP, boolean hasGaps) {

        LogUtil.info("historicalData()");
    }

    @Override
    public void scannerParameters(String xml) {

        LogUtil.info("scannerParameters()");
    }

    @Override
    public void scannerData(int reqId, int rank, ContractDetails contractDetails, String distance, String benchmark, String projection, String legsStr) {

        LogUtil.info("scannerData()");
    }

    @Override
    public void scannerDataEnd(int reqId) {

        LogUtil.info("scannerDataEnd()");
    }

    @Override
    public void realtimeBar(int reqId, long time, double open, double high, double low, double close, long volume, double wap, int count) {

        LogUtil.info("realtimeBar()");
    }

    @Override
    public void currentTime(long time) {

        LogUtil.info("currentTime()");
    }

    @Override
    public void fundamentalData(int reqId, String data) {

        LogUtil.info("fundamentalData()");
    }

    @Override
    public void deltaNeutralValidation(int reqId, UnderComp underComp) {

        LogUtil.info("deltaNeutralValidation()");
    }

    @Override
    public void tickSnapshotEnd(int reqId) {

        LogUtil.info("tickSnapshotEnd()");
    }

    @Override
    public void marketDataType(int reqId, int marketDataType) {

        LogUtil.info("marketDataType()");
    }

    @Override
    public void commissionReport(CommissionReport commissionReport) {

        LogUtil.info("commissionReport()");
    }

    @Override
    public void position(String account, Contract contract, int pos, double avgCost) {

        LogUtil.info("position()");
    }

    @Override
    public void positionEnd() {

        LogUtil.info("positionEnd()");
    }

    @Override
    public void accountSummary(int reqId, String account, String tag, String value, String currency) {

        LogUtil.info("accountSummary()");
    }

    @Override
    public void accountSummaryEnd(int reqId) {

        LogUtil.info("accountSummaryEnd()");
    }

    @Override
    public void verifyMessageAPI(String apiData) {

        LogUtil.info("verifyMessageAPI()");
    }

    @Override
    public void verifyCompleted(boolean isSuccessful, String errorText) {

        LogUtil.info("verifyCompleted()");
    }

    @Override
    public void displayGroupList(int reqId, String groups) {

        LogUtil.info("displayGroupList()");
    }

    @Override
    public void displayGroupUpdated(int reqId, String contractInfo) {
        LogUtil.info("displayGroupUpdated()");
    }

    @Override
    public void error(Exception e) {
        LogUtil.error("error",e);
    }

    @Override
    public void error(String str) {
        LogUtil.error("error"+str);
    }

    @Override
    public void error(int id, int errorCode, String errorMsg) {
        LogUtil.error("error,id="+id+",errorCode="+errorCode+",errorMsg"+errorMsg);
    }

    @Override
    public void connectionClosed() {
        LogUtil.info("connectionClosed()");
    }
}
